from settings import *
from random import randint
from cell_generator import cell_checker
from copy import deepcopy
import pygame

pygame.init()
screen = pygame.display.set_mode(resolution)
clock = pygame.time.Clock()

current_field = [[randint(0,1) for i in range(cells_width_count)] for i2 in range(cells_heigth_count)]
new_field = [[0 for i in range(cells_width_count)] for i2 in range(cells_heigth_count)]


while True:
    screen.fill("black")

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()

    for x in range(0, width, cell_size):
        pygame.draw.line(screen, cell_border_color, (x,0), (x, height))
    for y in range(0, height, cell_size):
        pygame.draw.line(screen, cell_border_color, (0,y), (width, y))

    for x in range(1, cells_width_count - 1):
        for y in range(1, cells_heigth_count - 1):
            if current_field[y][x]:
                pygame.draw.rect(screen, cell_color, (x * cell_size + 2, y * cell_size + 2, cell_size - 2, cell_size - 2))
            new_field[y][x] = cell_checker(current_field, x, y)

    current_field = deepcopy(new_field)

    print(f'FPS: {int(clock.get_fps())}')
    clock.tick(FPS_lock)
    pygame.display.flip()
